#include "includes/need-a-name.hh"
#include "includes/boundary-base.hh"
#include <vector>

BoundaryBase::BoundaryBase(){
  left.erase(left.begin(),left.end());
  right.erase(right.begin(),right.end());  
  std::vector<std::vector<std::string> >(left).swap(left);
  std::vector<std::vector<std::string> >(right).swap(right);  
  left = std::vector<std::vector<std::string> >(memory::phynumber+dataanalysis::auxnumber,  std::vector<std::string>(gridsetting::dimension));
  right = std::vector<std::vector<std::string> >(memory::phynumber+dataanalysis::auxnumber, std::vector<std::string>(gridsetting::dimension));
  for(int tmpp=0; tmpp<memory::phynumber; tmpp++)
    for(int tmpd=0; tmpd<gridsetting::dimension; tmpd++){
      left[tmpp][tmpd]="const";
      right[tmpp][tmpd]="const";
    }
}

BoundaryBase::~BoundaryBase(){
}

void BoundaryBase::set_parameter(std::string parakey,double paravalue){
  para[parakey]=paravalue;
}

void BoundaryBase::boundary_function(double* location, int index, double unitouternormalsum, double* var_j, double flag){
  // std::cout<< "boundary function"<<std::endl;
  for(int tmpp=0; tmpp<memory::phynumber; tmpp++)
      for(int tmpd=0; tmpd<gridsetting::dimension; tmpd++){
      // std::cout<< "boundary function --- reach here"<<std::endl;
	if(unitouternormalsum>0){
	  if(right[tmpp][tmpd]=="const")
	    const_boun(index,var_j,tmpp,flag);
	  if(right[tmpp][tmpd]=="zero")
	    zero_boun(var_j,tmpp,flag);
	  if(right[tmpp][tmpd]=="special")
	    special_boun(location,index,unitouternormalsum,var_j,tmpp,tmpd,flag);
	}
	if(unitouternormalsum<0){
	  if(left[tmpp][tmpd]=="const")
	    const_boun(index,var_j,tmpp,flag);
	  if(left[tmpp][tmpd]=="zero")
	    zero_boun(var_j,tmpp,flag);
	  if(left[tmpp][tmpd]=="special")
	    special_boun(location,index,unitouternormalsum,var_j,tmpp,tmpd,flag);
	}
    }
}

void BoundaryBase::special_boun(double* location, int index, double unitouternormalsum, double* var_j, int tmpp, int tmpd, double flag){
}

void BoundaryBase::const_boun(int index, double* var_j, int tmpp, double flag){
  // std::cout << "constant boundary - index: " << index <<std::endl;  
  // if(flag==-1.0)
  //     std::cout << " - for LeftValue: " <<std::endl;
  // if(flag==1.0)
  //     std::cout << " - for RightValue: " <<std::endl;

  if(flag==-1.0)
     basis.getOnePhyLeft(index,tmpp,var_j);
   if(flag==1.0)
     basis.getOnePhyRight(index,tmpp,var_j);
   if(flag==0.0)
     basis.getOnePhyMiddle(index,tmpp,var_j);
}

void BoundaryBase::const_boun(int index, double* var_j, int tmpp){
  var_j[tmpp]=memory::variable[tmpp][index];
}

void BoundaryBase::zero_boun(double* var_j, int tmpp, double flag){
  var_j[tmpp]=0.0;  
}

